<!DOCTYPE html>
<html ng-app>
<head>
	<title></title>
	<title>AAA订座</title>
    <!-- Bootstrap core CSS -->
    <link href="/libs/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="/libs/dashboard.css" rel="stylesheet">
    <script type="text/javascript" src="/libs/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="/libs/angular.js"></script>
	<style type="text/css">
	html {
		height: 100%;
	}
	body {
		height: 100%;
	}
	.contain {
		height: 100%;
		width: 100%;
		background: rgba(0,0,0,0.5);
		position: absolute; 
		left: 0;
		display: none;
		top: 0;
	}
	.table2 {
		
	
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		margin: auto;
	}
	* {
		margin: 0;
		padding: 0;
		list-style: none;
	}
	
	.edit {
		display: none;
	}
	.success,.fail {
		display: none;
	}
	table,th {
		text-align: center;
		font-size: 20px;
	}
	.alert {
		display: none;
	}
	</style>
</head>


<body>

<h2>欢迎<%=username%></h2>
	 <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/">AAA订座系统</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
          	<li><a href="/">首页</a></li>
            <li><a href="javascript:;">欢迎你,<%= username %></a></li>
            <li><a href="/loginout">退出登录</a></li>
            
          </ul>
            <div ng-show="<%= manger ? false : true %>">
               <form action="/search" class="navbar-form navbar-right">
                  <input type="text" name="name" class="form-control" placeholder="Search...">
              </form>
            </div>
          
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <ul class="nav nav-sidebar">
            <li><a href="/create">创建班级</a></li>
            <li><a href="/detail?act=m">位置管理</a></li>
            <li><a href="/allClass">班级管理</a></li>
            <li class="active"><a href="/quanxian?name=<%= username %>" onclick="quanxian()" ng-show="<%= username== 'admin' ? true : false;%>">权限管理</a></li>
          </ul>
       
         
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div class="jumbotron">
        		<% if (!data.length) {%>
					<h2>暂无人注册</h2>
				<%} else {%>
					<form action="/quanxian" method="post" class="updateForm">
					<table class="table table-hover">
						<tr>
							<th>班级</th>
							<th>操作</th>
						</tr>
						<%for (var i = 0;i < data.length;i++) {%>
						<tr>
							<td><%= data[i].name%></td>
							<td><input type="checkbox"  ng-checked="<%= data[i].manger ? true : false %>" ><input type="hidden"  value="<%= data[i].id %>"></td>
						
						
						</tr>
						
					<%}%>
					</table>
					<input type="submit" class="btn btn-success" value="确认更改">
					</form>
					
					
				<%}%>
				
				<!-- 成功失败 -->
			
				<div class="alert alert-warning alert-dismissible" role="alert">
				  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
				  	<span aria-hidden="true">&times;</span>
					</button>
				  <strong></strong> 
				</div>
			
		</div>
          
      </div>
    </div>
	
	

</body>
</html>

<script type="text/javascript">
	$('.updateForm').submit(function () {
		// var dataArr = [];
		$('.updateForm td').each(function () {
			
			if ($(this).children().length == 2) {
				var json = {
					manger: $(this).children()[0].checked ? 1 : 0,
					id: $(this).children().eq(1).val()
				};

				$.ajax({
					type: 'post',
					data: json,
					success: function (s) {
						
						if ($.err) {
							$('.alert').show().children('strong').html('更新失败');
						} else {
							$('.alert').show().children('strong').html('更新成功');
						}
					}
				});
			}
		})
		return false;
	});
	$('.close').click(function () {
		$('.alert').hide();
	});
</script>